package com.lemon.common.web.listener;

import com.lemon.common.context.SessionContext;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

/**
 * Session 监听
 *
 * @author ymh
 * @date 2019-04-06 09:04
 */
@Slf4j
@WebListener
public class SessionListener implements HttpSessionListener {

    private SessionContext sessionContext = SessionContext.getInstance();

    @Override
    public void sessionCreated(HttpSessionEvent se) {
        log.info("添加session " + se.getSession().getId());
        HttpSession session = se.getSession();
        sessionContext.addSession(session);
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent se) {
        HttpSession session = se.getSession();
        sessionContext.delSession(session);
    }
}
